$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'springlamb/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true },
			{ label: '时间', name: 'shijian', index: 'shijian', width: 80 }, 			
			{ label: '干草量', name: 'busiliangGancao', index: 'busiliang_gancao', width: 80 }, 			
			{ label: '精料量', name: 'busiliangJingliao', index: 'busiliang_jingliao', width: 80 }, 			
			{ label: '干草费用', name: 'busiMoneyGancao', index: 'busi_money_gancao', width: 80 }, 			
			{ label: '精料费用', name: 'busiMoneyJingliao', index: 'busi_money_jingliao', width: 80 }, 			
			{ label: '总补饲成本', name: 'busiMoneyTotal', index: 'busi_money_total', width: 80 }, 			
			{ label: '雇牧工成本', name: 'totalMonth', index: 'total_month', width: 80 }, 			
			{ label: '不雇牧工成本', name: 'totalMonthNot', index: 'total_month_not', width: 80 }, 			
			{ label: '雇牧工累积成本', name: 'totalMonthCumsum', index: 'total_month_cumsum', width: 80 }, 			
			{ label: '不雇牧工累积成本', name: 'totalMonthCumsumNot', index: 'total_month_cumsum_not', width: 80 }, 			
			{ label: '无补贴净利润', name: 'profitsSigleNot', index: 'profits_sigle_not', width: 80 }, 			
			{ label: '净利润', name: 'profitsSigle', index: 'profits_sigle', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
        yue:'',
		springLamb: {}
    },
	methods: {
		query: function () {
			vm.reload();
		},
        timequery: function (event) {
            //input.focus();
            //alert(vm.starttime);
            $("#jqGrid").jqGrid('setGridParam',{
                url:baseURL + 'springlamb/timelist',
                postData:{
                    'shijian':vm.yue,

                },
                datattype:'json',
                mtyp:'GET',
                viewrecords: true,
                height: 385,
                rowNum: 10,
                rowList : [10,30,50],
                rownumbers: true,
                rownumWidth: 25,
                autowidth:true,
                multiselect: true,
                pager: "#jqGridPager",
                jsonReader : {
                    root: "page.list",
                    page: "page.currPage",
                    total: "page.totalPage",
                    records: "page.totalCount"
                },
                prmNames : {
                    page:"page",
                    rows:"limit",
                    order: "order"
                },
            }).trigger('reloadGrid');


        },
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.springLamb = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.springLamb.id == null ? "springlamb/save" : "springlamb/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.springLamb),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "springlamb/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "springlamb/info/"+id, function(r){
                vm.springLamb = r.springLamb;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});